#include "Sprite.h"

#include <d3dx9.h>


struct CUSTOMVERTEX
{
	float x, y, z; // The transformed position for the vertex
	float u,v;
};


VKSprite::VKSprite()
{
	m_pDevice = NULL;
	m_pTexture = NULL;

	dwVertexType  = D3DFVF_XYZ| D3DFVF_TEX1;
}

VKSprite::~VKSprite(void)
{
	if(m_pTexture)
	m_pTexture->Release();
}

HRESULT VKSprite::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	CUSTOMVERTEX Vertices[] =
	{
		{ pImageSize->left , pImageSize->bottom , 0.0f , 0.0f ,  0.0f } , 
		{ pImageSize->left , pImageSize->top , 0.0f , 0.0f ,  1.0f } , 
		{ pImageSize->right , pImageSize->bottom , 0.0f , 1.0f ,  0.0f  },
		{ pImageSize->right , pImageSize->top, 0.0f , 1.0f , 1.0f }
	};

	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);

	return S_OK;
}


HRESULT VKSprite::Render()
{
	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);
	m_pDevice->SetTexture(0,m_pTexture);
	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX) );
	m_pDevice->SetFVF( dwVertexType );
	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	return S_OK;
}



//////////////////////////////////////////////////////////////////////////

struct CUSTOMVERTEX2
{
	D3DXVECTOR3 vecPos;
};


VKSprite2::VKSprite2()
{
	m_pDevice = NULL;
	m_pTexture = NULL;

	dwVertexType  = D3DFVF_XYZ;
}

VKSprite2::~VKSprite2(void)
{
	if(m_pTexture)
	m_pTexture->Release();
}


HRESULT VKSprite2::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	CUSTOMVERTEX2 Vertices[] =
	{
		D3DXVECTOR3(pImageSize->left , pImageSize->bottom , 0.0f ) , 
		D3DXVECTOR3(pImageSize->left , pImageSize->top , 0.0f ) , 
		D3DXVECTOR3(pImageSize->right , pImageSize->bottom , 0.0f ) , 
		D3DXVECTOR3(pImageSize->right , pImageSize->top , 0.0f ) , 
	};

	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX2), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);
	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = 10.0f;
	m_matPos._22 = 10.0f;
	m_matPos._41 = 0.0f;
	m_matPos._42 = 0.0f;

	D3DXMatrixIdentity(&m_matTex);
	m_matTex._11 = 0.0f ;
	m_matTex._32 = 0.0f ;
// 	m_matTex._22 = 0.5f ;
// 	m_matTex._41 = 1.0f;
// 	m_matTex._42 = 1.0f;
	nAngle = 0;

	return S_OK;
}

void VKSprite2::SetPos(D3DXVECTOR3 vecPos , D3DXVECTOR2 vecSize)
{
	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = vecSize.x;
	m_matPos._22 = vecSize.y;
	m_matPos._41 = vecPos.x;
	m_matPos._42 = vecPos.y;
}
#include <iostream>
using namespace std;

HRESULT VKSprite2::Render()
{
	++nAngle;
	float fRad = (nAngle*D3DX_PI) /360;
	D3DXMatrixRotationX(&m_matTex , fRad);

	cout << nAngle << endl;

	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);

	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
	m_pDevice->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
	m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

	m_pDevice->SetTexture(0,m_pTexture);
	m_pDevice->SetTransform(D3DTS_TEXTURE0 , &m_matTex);
	m_pDevice->SetTransform(D3DTS_TEXTURE1 , &m_matTex);
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
	m_pDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );


// 	m_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
// 	m_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
// 	m_pDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, 0x000000ff);

	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX2) );
	m_pDevice->SetFVF( dwVertexType );
	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	m_pDevice->SetRenderState(D3DRS_LIGHTING , TRUE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );
//	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );

	return S_OK;
}










//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

struct CUSTOMVERTEX3
{
	D3DXVECTOR3 vecPos;
};


VKSprite3::VKSprite3()
{
	m_pDevice = NULL;
	m_pTexture = NULL;
	m_ppDecl	= 0;

	dwVertexType  = D3DFVF_XYZ;
}

VKSprite3::~VKSprite3(void)
{
	if(m_pTexture)
		m_pTexture->Release();
}


HRESULT VKSprite3::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	CUSTOMVERTEX3 Vertices[4] =
	{
		{ D3DXVECTOR3(pImageSize->left , pImageSize->bottom    , 0.0f )  },
		{ D3DXVECTOR3(pImageSize->left , pImageSize->top         , 0.0f ) },  
		{ D3DXVECTOR3(pImageSize->right , pImageSize->bottom  , 0.0f ) }, 
		{ D3DXVECTOR3(pImageSize->right , pImageSize->top       , 0.0f ) }
	};


	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX3), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);

	D3DXCreateTextureFromFile(pDevice , "tex_a.tga" , &m_pAlphaTex);

	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = 10.0f;
	m_matPos._22 = 10.0f;
	m_matPos._41 = 0.0f;
	m_matPos._42 = 0.0f;

	m_matTex._11 = 1.0f ;
	m_matTex._22 = 1.0f ;
	m_matTex._41 = 1.0f;
	m_matTex._42 = 1.0f;
	fAngle = 0;

	return S_OK;
}

void VKSprite3::SetPos(D3DXVECTOR3 vecPos , D3DXVECTOR2 vecSize)
{
	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = vecSize.x;
	m_matPos._22 = vecSize.y;
	m_matPos._41 = vecPos.x;
	m_matPos._42 = vecPos.y;
}



HRESULT VKSprite3::Render()
{
	fAngle -= 0.003f;
	D3DXMatrixRotationX(&m_matTex , fAngle);

	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );

	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

	m_pDevice->SetTextureStageState(1,  D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );

	m_pDevice->SetTextureStageState(1 , D3DTSS_COLOROP,  D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG2 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG1 , D3DTA_CURRENT);

	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAOP , D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG2 , D3DTA_DIFFUSE);

	m_pDevice->SetTransform(D3DTS_TEXTURE0 , &m_matTex);

	m_pDevice->SetTexture(0, m_pTexture);
	m_pDevice->SetTexture(1 , m_pAlphaTex);

	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX3) );
	m_pDevice->SetFVF( dwVertexType );
	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	
	m_pDevice->SetRenderState(D3DRS_LIGHTING , TRUE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
	m_pDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,D3DTOP_DISABLE );
	m_pDevice->SetTextureStageState( 1, D3DTSS_COLOROP,  D3DTOP_DISABLE );

	return S_OK;
}



//////////////////////////////////////////////////////////////////////////

struct CUSTOMVERTEX4
{
	float x, y, z; // The transformed position for the vertex
	float u,v;
};


VKSprite4::VKSprite4()
{
	m_pDevice = NULL;
	m_pTexture = NULL;

	dwVertexType  = D3DFVF_XYZ| D3DFVF_TEX1;
}

VKSprite4::~VKSprite4(void)
{
	if(m_pTexture)
		m_pTexture->Release();
}

HRESULT VKSprite4::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	CUSTOMVERTEX4 Vertices[] =
	{
		{ pImageSize->left , pImageSize->bottom , 0.0f , 0.0f ,  0.0f } , 
		{ pImageSize->left , pImageSize->top , 0.0f , 0.0f ,  1.0f } , 
		{ pImageSize->right , pImageSize->bottom , 0.0f , 1.0f ,  0.0f  },
		{ pImageSize->right , pImageSize->top, 0.0f , 1.0f , 1.0f }
	};

	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX4), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);

	return S_OK;
}


HRESULT VKSprite4::Render()
{
	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);

	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,	TRUE );
	m_pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0xAAFFFFFF);

	m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,	D3DTOP_MODULATE );
	m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1,	D3DTA_TEXTURE );
	m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2,	D3DTA_TFACTOR );

	m_pDevice->SetTexture(0,m_pTexture);
	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX4) );
	m_pDevice->SetFVF( dwVertexType );
	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	m_pDevice->SetRenderState(D3DRS_LIGHTING , TRUE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,	FALSE );
	m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,	D3DTOP_DISABLE );
	m_pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0xFFFFFFFF);

	return S_OK;
}







//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

struct CUSTOMVERTEX5
{
	D3DXVECTOR3 vecPos;
};


VKSprite5::VKSprite5()
{
	m_pDevice = NULL;
	m_pTexture = NULL;
	m_ppDecl	= 0;

	dwVertexType  = D3DFVF_XYZ;
}

VKSprite5::~VKSprite5(void)
{
	if(m_pTexture)
		m_pTexture->Release();
}


HRESULT VKSprite5::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	CUSTOMVERTEX5 Vertices[4] =
	{
		{ D3DXVECTOR3(pImageSize->left , pImageSize->bottom    , 0.0f )  },
		{ D3DXVECTOR3(pImageSize->left , pImageSize->top         , 0.0f ) },  
		{ D3DXVECTOR3(pImageSize->right , pImageSize->bottom  , 0.0f ) }, 
		{ D3DXVECTOR3(pImageSize->right , pImageSize->top       , 0.0f ) }
	};


	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX5), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);

	D3DXCreateTextureFromFile(pDevice , "tex_a.tga" , &m_pAlphaTex);

	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = 10.0f;
	m_matPos._22 = 10.0f;
	m_matPos._41 = 0.0f;
	m_matPos._42 = 0.0f;

	m_matTex._11 = 1.0f ;
	m_matTex._22 = 1.0f ;
	m_matTex._41 = 1.0f;
	m_matTex._42 = 1.0f;
	fAngle = 0;

	return S_OK;
}

void VKSprite5::SetPos(D3DXVECTOR3 vecPos , D3DXVECTOR2 vecSize)
{
	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = vecSize.x;
	m_matPos._22 = vecSize.y;
	m_matPos._41 = vecPos.x;
	m_matPos._42 = vecPos.y;
}

D3DXMATRIX matOriginal;

HRESULT VKSprite5::Render()
{
	D3DXMatrixIdentity(&matOriginal);

	fAngle -= 0.001f;
	D3DXMatrixRotationX(&m_matTex , fAngle);

	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );

	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

	m_pDevice->SetTextureStageState(1,  D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLOROP,  D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG2 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG1 , D3DTA_CURRENT);

	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAOP , D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG2 , D3DTA_DIFFUSE);

	m_pDevice->SetTransform(D3DTS_TEXTURE0 , &matOriginal);
	m_pDevice->SetTransform(D3DTS_TEXTURE1 , &m_matTex);
	m_pDevice->SetTexture(0, m_pTexture);
	m_pDevice->SetTexture(1 , m_pAlphaTex);

	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX5) );
	m_pDevice->SetFVF( dwVertexType );
	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );
	m_pDevice->SetTextureStageState( 0 , D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 0 , D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_ALPHAOP,D3DTOP_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_COLOROP,  D3DTOP_DISABLE );

	return S_OK;
}



//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

struct CUSTOMVERTEX6
{
	D3DXVECTOR3 vecPos;
};
VKSprite6::VKSprite6()
{
	m_pDevice = NULL;
	m_pTexture = NULL;
	m_ppDecl	= 0;

	dwVertexType  = D3DFVF_XYZ;
}

VKSprite6::~VKSprite6(void)
{
	if(m_pTexture)
		m_pTexture->Release();
}


HRESULT VKSprite6::Load(LPDIRECT3DDEVICE9 pDevice , const char* strFile ,FRECT* pImageSize)
{
	m_pDevice = pDevice;

	D3DVERTEXELEMENT9 decl[] = 
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },  // XYZRHW
		D3DDECL_END()


//		{ 1, sizeof(float) * 4, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD }
	};

	CUSTOMVERTEX6 Vertices[4] =
	{
		{ D3DXVECTOR3(pImageSize->left , pImageSize->bottom    , 0.0f )  },
		{ D3DXVECTOR3(pImageSize->left , pImageSize->top         , 0.0f ) },  
		{ D3DXVECTOR3(pImageSize->right , pImageSize->bottom  , 0.0f ) }, 
		{ D3DXVECTOR3(pImageSize->right , pImageSize->top       , 0.0f ) }
	};

	HRESULT hr = m_pDevice->CreateVertexDeclaration(decl, &m_ppDecl);

	if( FAILED( m_pDevice->CreateVertexBuffer( 4 * sizeof(CUSTOMVERTEX6), 0, dwVertexType, D3DPOOL_DEFAULT, &m_pVBuff, NULL ) ) )		throw E_FAIL;

	VOID* pVertices;
	if( FAILED( m_pVBuff->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )		throw E_FAIL;

	memcpy( pVertices, Vertices, sizeof(Vertices) );
	m_pVBuff->Unlock();

	D3DXCreateTextureFromFile(pDevice , strFile , &m_pTexture);

	D3DXCreateTextureFromFile(pDevice , "tex_a.tga" , &m_pAlphaTex);

	D3DXMatrixIdentity(&m_matPos);

	m_matPos._11 = 10.0f;
	m_matPos._22 = 10.0f;
	m_matPos._41 = 0.0f;
	m_matPos._42 = 0.0f;

	m_matTex._11 = 1.0f ;
	m_matTex._22 = 1.0f ;
	m_matTex._41 = 1.0f;
	m_matTex._42 = 1.0f;
	fAngle = 0;

	return S_OK;
}

void VKSprite6::SetPos(D3DXVECTOR3 vecPos , D3DXVECTOR2 vecSize)
{
	D3DXMatrixIdentity(&m_matPos);
//	D3DXMatrixOrthoOffCenterLH(&m_matPos, vecPos.x, vecPos.x + vecSize.x, vecPos.y, vecPos.y + vecSize.y, -1.0f, 1.0f);
	D3DXMatrixOrthoOffCenterLH(&m_matPos, 0,1,1,0, 1.0f, 1.0f);
// 
// 	m_matPos._11 = vecSize.x;
// 	m_matPos._22 = vecSize.y;
// 	m_matPos._41 = vecPos.x;
// 	m_matPos._42 = vecPos.y;

	D3DXMatrixIdentity(&m_matTex);

	m_matTex._11 = 1.0f;
	m_matTex._22 = 1.0f;
	m_matTex._41 = 0.0f;
	m_matTex._42 = 0.0f;

}

D3DXMATRIX matOriginal2;

HRESULT VKSprite6::Render()
{
	D3DXMatrixIdentity(&matOriginal2);

//	fAngle -= 0.001f;
//	D3DXMatrixRotationX(&m_matTex , fAngle);

	m_pDevice->SetRenderState(D3DRS_LIGHTING , FALSE);
	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );

	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

	m_pDevice->SetTextureStageState(1,  D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
	m_pDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

	m_pDevice->SetTextureStageState(1 , D3DTSS_COLOROP,  D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG2 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_COLORARG1 , D3DTA_CURRENT);

	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAOP , D3DTOP_SELECTARG1 );
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE);
	m_pDevice->SetTextureStageState(1 , D3DTSS_ALPHAARG2 , D3DTA_DIFFUSE);

	D3DXMatrixIdentity(&m_matPos);
	D3DXMatrixOrthoOffCenterLH(&m_matPos, 0,10,10,0, -1.0f, 1.0f);

	m_pDevice->SetTransform(D3DTS_WORLD, &m_matPos);
	m_pDevice->SetTransform(D3DTS_TEXTURE0 , &m_matPos);
	m_pDevice->SetTransform(D3DTS_TEXTURE1 , &m_matTex);
	
	m_pDevice->SetVertexDeclaration(m_ppDecl);

	m_pDevice->SetStreamSource( 0, m_pVBuff, 0, sizeof(CUSTOMVERTEX6) );

	m_pDevice->SetTexture(0, m_pTexture);
	m_pDevice->SetTexture(1 , m_pAlphaTex);

	m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );
	m_pDevice->SetTextureStageState( 0 , D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 0 , D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_ALPHAOP,D3DTOP_DISABLE );
	m_pDevice->SetTextureStageState( 1 , D3DTSS_COLOROP,  D3DTOP_DISABLE );

	return S_OK;
}
